/**
 * 
 */
package com.mrroman.linksender.gui.actions;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ResourceBundle;

import javax.swing.AbstractAction;

import com.mrroman.linksender.Configuration;
import com.mrroman.linksender.ioc.In;
import com.mrroman.linksender.ioc.Init;
import com.mrroman.linksender.ioc.Locales;
import com.mrroman.linksender.ioc.Name;

/**
 * 
 * @author mrozekon
 *
 */
@Name("actions.HideGroupMessagesAction")
public class HideGroupMessagesAction extends AbstractAction {
	
	@Locales
	private ResourceBundle messages;
    
    @In
    private Configuration configuration;

	@Init
	public void init() {
		putValue(NAME, messages.getString("hide_group_messages"));
		putValue(SELECTED_KEY, configuration.isHideGroupMessages());
		
		configuration.addPropertyChangeListener(new PropertyChangeListener() {
			@Override
			public void propertyChange(PropertyChangeEvent evt) {
				if (evt.getPropertyName().equals(Configuration.PROP_HIDEGROUPMESSAGES)) {
					putValue(SELECTED_KEY, evt.getNewValue());
					firePropertyChange(SELECTED_KEY, evt.getOldValue(), evt.getNewValue());
				}
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		configuration.setHideGroupMessages((Boolean)getValue(SELECTED_KEY));
	}

}
